<template>
  <div>
    <el-card class="box-card" style="margin-top: 0;">
      <div slot="header" class="clearfix">
        <span>筛选查询</span>
      </div>
      <div class="text item">
        <el-form
          :model="queryParams"
          ref="queryForm"
          :inline="true"
        >
          <el-form-item label="" prop="jiguanProvince">
            <el-select
              v-model="queryParams.jiguanProvince"
              placeholder="所在省份"
              clearable
              size="small"
              @change="changeProvince"
            >
              <el-option
                v-for="(item, index) in provinceList"
                :key="index"
                :label="item.provinceName"
                :value="item.provinceId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="jiguanCity">
            <el-select
              v-model="queryParams.jiguanCity"
              placeholder="所在城市"
              clearable
              size="small"
            >
              <el-option
                v-for="(item, index) in cityList"
                :key="index"
                :label="item.name"
                :value="item.cityId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="school">
            <el-input
              v-model="queryParams.school"
              placeholder="请输入所在中学"
              clearable
              size="small"
            />
          </el-form-item>
          <el-form-item label="" prop="status">
            <el-select
              v-model="signStatus"
              placeholder="请选择报名状态"
              clearable
              size="small"
              @change="changeSignStatus"
            >
              <el-option
                v-for="(item, index) in statusOptions"
                :key="index"
                :label="item.dictLabel"
                :value="item.dictValue"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="phone">
            <el-input
              v-model="queryParams.phone"
              placeholder="请输入手机号"
              clearable
              size="small"
            />
          </el-form-item>
          <el-form-item label="" prop="idCard">
            <el-input
              v-model="queryParams.idCard"
              placeholder="请输入身份证号"
              clearable
              size="small"
            />
          </el-form-item>

          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
            >搜索
            </el-button
            >
            <el-button
              type="primary"
              icon="el-icon-refresh"
              size="mini"
              @click="resetQuery"
            >重置
            </el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </el-card>

    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>数据列表</span>

        <el-button
          type="primary"
          size="mini"
          style="float: right; margin-left: 10px;"
          @click="handleExport"
          v-hasPermi="['campSystem:campManager:signup:export']"
        >导出全量表
        </el-button>
      </div>
      <div class="text item">
        <el-table v-loading="loading" :data="tableList">
          <el-table-column label="报名时间" align="center" prop="addTime"/>
          <el-table-column label="所在省份" align="center" prop="jiguanProvince"/>
          <el-table-column label="所在中学" align="center" prop="school"/>
          <el-table-column label="姓名" align="center" prop="name"/>
          <el-table-column label="手机号" align="center" prop="phone"/>
          <el-table-column label="身份证号" align="center" prop="idCard"/>
          <el-table-column label="邀请码ID" align="center" prop="invitationCode"/>
          <el-table-column label="报名成功时间" align="center" prop="payTime"/>
          <el-table-column label="报名状态" align="center" prop="qianDuanStatus"/>
          <el-table-column label="支付金额" align="center" prop="payAmount"/>
          <el-table-column label="操作" align="center" min-width="120px">
            <template slot-scope="scope">
              <el-button
                v-if="Number(scope.row.status)>3"
                size="mini"
                type="text"
                @click="handleView(scope.row)"
              >查看</el-button>
              <el-button
                v-if="Number(scope.row.status)>3"
                size="mini"
                type="text"
                @click="handleEdit(scope.row)"
              >编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.page"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
    <!--审核报名资料弹框-->
    <check-form
      :dialogVisibleFu="dialogVisibleFu"
      :phoneFu="phoneFu"
      :campsiteIdFu="idFu"
      :typeFu="2"
      titleFu="查看报名资料"
      @closeDialog="closeDialog"
    ></check-form>
    <!--编辑用户信息弹框-->
    <edit-user-form
      :dialogVisibleFu="dialogVisibleEditFu"
      :phoneFu="phoneFu"
      :campsiteIdFu="idFu"
      :typeFu="2"
      titleFu="编辑用户信息"
      @closeDialog="closeDialogEdit"
    ></edit-user-form>
  </div>
</template>

<script>
  import {GetProvinceList, GetCityList, GetSignUpList} from "@/api/campSystem/campOper";
  import CheckForm from "@/components/CampSystem/CampOper/Check/CheckForm";
  import EditUserForm from "@/components/CampSystem/CampOper/Check/EditUserForm";
  export default {
    name: "SignUpInfo",
    components:{CheckForm,EditUserForm},
    props: {
      idFu: [String, Number]
    },
    data() {
      return {
        loading: false,// 表格加载loading
        queryParams: {
          page: 1,
          pageSize: 10,
          campsiteId: null,
          jiguanProvince: null,
          jiguanCity: null,
          school: null,
          status: null,
          examineStatus: null,
          invitationCode: null,
          phone: null,
          idCard: null,
        },
        total: 0,// 数据总条数
        tableList: [], // 表格数据列表
        signStatus: null,// 报名状态select框绑定值
        statusOptions: [], // 营地报名状态列表
        provinceList: [],// 省份列表
        cityList: [],// 城市列表
        dialogVisibleFu: false,// 控制审核报名资料弹框的显示隐藏
        dialogVisibleEditFu: false,// 控制编辑用户信息弹框的显示隐藏
        phoneFu: '',// 当前审核弹框的phone
        idCardFu: '',// 当前审核弹框的idCard
      };
    },
    created() {
      this.queryParams.campsiteId = this.idFu;
      this.getDicts("camp_signup_status2").then(response => {
        this.statusOptions = response.data;
      });
      this.getProvince();
      this.getList();
    },
    methods: {
      // 改变报名状态-搜索框
      changeSignStatus(val){
        let arr = val.split(',')
        if(arr[0]){
          this.queryParams.status = Number(arr[0]);
        }else{
          this.queryParams.status = null;
        }
        if(arr[1]){
          this.queryParams.examineStatus = Number(arr[1]);
        }else{
          this.queryParams.examineStatus = null;
        }
        if(arr[2]){
          this.queryParams.invitationCode = arr[2];
        }else{
          this.queryParams.invitationCode = null;
        }
        console.log(this.queryParams.status,this.queryParams.examineStatus,this.queryParams.invitationCode)
      },
      // 关闭编辑用户信息弹框，子组件触发
      closeDialogEdit(val, type){
        this.dialogVisibleEditFu = val;
        if(type){
          this.getList();
        }
      },
      // 编辑按钮
      handleEdit(data){
        this.phoneFu = data.phone;
        this.dialogVisibleEditFu = true;
      },
      // 关闭审核报名资料弹框，子组件触发
      closeDialog(val){
        this.dialogVisibleFu = val;
      },
      // 查看按钮
      handleView(data){
        this.phoneFu = data.phone;
        this.dialogVisibleFu = true;
      },
      // 重置按钮
      resetQuery() {
        this.cityList = [];
        this.signStatus = null;
        this.queryParams.status = null;
        this.queryParams.examineStatus = null;
        this.queryParams.invitationCode = null;
        this.$refs['queryForm'].resetFields();
        this.handleQuery();
      },
      // 搜索按钮
      handleQuery() {
        this.queryParams.page = 1;
        this.queryParams.pageSize = 10;
        this.getList();
      },
      // 获取列表
      getList() {
        this.loading = true;
        GetSignUpList(this.queryParams)
          .then(response => {
            console.log(response);
            if (response.code != 200) {
              this.loading = false;
              return this.msgError(response.msg);
            }
            this.tableList = response.data;
            this.total = response.total;
            this.loading = false;
          })
          .catch(error => {
            console.log(error);
            this.loading = false;
          });
      },
      // 改变省份，获取城市列表
      changeProvince(value) {
        GetCityList(value+'').then((res) => {
          if(res.code != 200){
            return this.$message.error(res.msg);
          }
          this.cityList = res.data;
          this.queryParams.jiguanCity = null;
          console.log(res)
        }).catch(err=>{
          console.log(err);
        });
      },
      // 获取省份列表
      getProvince() {
        GetProvinceList()
          .then(response => {
            this.provinceList = response;
          })
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download(
          "modules-campsite/conf/NewExport",
          {
            campsiteId: this.queryParams.campsiteId
          },
          `报名信息全量表.xlsx`
        );
      },
    },
    watch: {
      idFu(val) {
        this.queryParams.campsiteId = val;
        this.getList();
      },
    }
  }
</script>

<style lang="scss">
  @import "@/assets/styles/card.scss";
</style>

